# coding=utf-8
# !/usr/bin/env python

import time
import logging.handlers
from app import create_app
from flask_script import Manager

app = create_app('default')  # 调用工长函数实例化Flask app
manager = Manager(app)


# 'python manage.py test' 启动单元测试
@manager.command
def test():
    """Run the unit tests."""
    import unittest
    tests = unittest.TestLoader().discover('test')
    unittest.TextTestRunner(verbosity=2).run(tests)


if __name__ == '__main__':
    # 日志设置
    handler = logging.FileHandler('log/myCalc_' + time.strftime('%Y-%m-%d', time.localtime(time.time())) + '.log', encoding='UTF-8')
    logging_format = logging.Formatter('[%(asctime)s] - %(levelname)s - %(filename)s - %(funcName)s (%(lineno)s) - %(message)s')
    handler.setFormatter(logging_format)
    handler.setLevel(logging.DEBUG)
    app.debug = True
    app.logger.addHandler(handler)

    manager.run()
